<?php

namespace Modules\Shop\Entities;

use Illuminate\Database\Eloquent\Model;
use houdunwang\arr\Arr;
class Category extends Model
{
    protected $guarded = [];
    public function fenlei(){
    	return $this->belongsTo (Category::class,'pid','id');
	}
	public static function getTreeCategory($cate = null){
    	$data = self::get ();
    	if(!is_null ($cate)){
    		foreach ($data as $k => $v){
    			$data[$k]['_selected'] = $cate['pid'] == $v['id'];
    			$data[$k]['_disabled'] = $cate['id'] == $v['id'] || Arr::isChild(
    		$data,$v['id'],$cate['id'],'id','pid');
			}
		}
    	$category = Arr::tree($data ? $data->toArray () : [],'cname','id','pid');
    	//dd ($category);
    	return $category;
	}
	public static function hasChildCategory($cate){
    	$data = self::get();
    	return Arr::hasChild($data,$cate['id'],'pid');
	}
}
